package cn.enjoy.boot.entity;

import lombok.Data;

/**
 * @author K
 * @date 2024-03-19 16:08
 */
@Data
public class Person implements Cloneable {
    private String name;
    private Address address;

    public Person(String name, Address address) {
        this.name = name;
        this.address = address;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Data
    static class Address {
        private String street;
        private int number;
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        Address address = new Address();
        address.setStreet("123 Main St");
        address.setNumber(123);

        Person originalUser = new Person("John Doe", address);
        // shallowCopyUser 是 originalUser 的浅拷贝，
        // 它们的 address 属性仍然指向同一个 Address 对象。
        Person shallowCopyUser = (Person) originalUser.clone();
        System.out.println();
        address.setNumber(456);
        System.out.println();
    }
}
